using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Clue_Less_Client.localhost;

namespace Clue_Less_Client
{
    public partial class Accuse : Form
    {
        private int _gameID;
        private Player _player;
        private MainForm _frm;
        private bool _isAccuse = true;

        public Accuse(MainForm frm)
        {
            _gameID = frm.GameID;
            _player = frm.Player;
            _frm = frm;
            InitializeComponent();
        }

        private void Accuse_Load(object sender, EventArgs e)
        {
            btnAccuse.Text = "Accuse";
            List<ComboBoxItem> rooms = new List<ComboBoxItem>();
            foreach (Rooms key in Images.roomCards.Keys)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Value = key.ToString();
                item.Label = key.ToString();
                rooms.Add(item);
            }
            
            cbRooms.DataSource = rooms;
            cbRooms.DisplayMember = "Label";
            cbRooms.ValueMember = "Value";

            List<ComboBoxItem> weapons = new List<ComboBoxItem>();
            foreach (Weapons key in Images.weaponCards.Keys)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Value = key.ToString();
                item.Label = key.ToString();
                weapons.Add(item);
            }

            cbWeapons.DataSource = weapons;
            cbWeapons.DisplayMember = "Label";
            cbWeapons.ValueMember = "Value";

            List<ComboBoxItem> characters = new List<ComboBoxItem>();
            foreach (Characters key in Images.characterCards.Keys)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Value = key.ToString();
                item.Label = key.ToString();
                characters.Add(item);
            }

            cbCharacter.DataSource = characters;
            cbCharacter.DisplayMember = "Label";
            cbCharacter.ValueMember = "Value";
        }

        private void cbRooms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbRooms.SelectedIndex >= 0)
            {
                pictureBox1.Image = Images.roomCards[(Rooms)Enum.Parse(typeof(Rooms), ((ComboBoxItem)cbRooms.SelectedItem).Value)];
            }
        }

        private void cbWeapons_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbWeapons.SelectedIndex >= 0)
            {
                pictureBox2.Image = Images.weaponCards[(Weapons)Enum.Parse(typeof(Weapons), ((ComboBoxItem)cbWeapons.SelectedItem).Value)];
            }
        }

        private void cbCharacter_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbCharacter.SelectedIndex >= 0)
            {
                pictureBox3.Image = Images.characterCards[(Characters)Enum.Parse(typeof(Characters), ((ComboBoxItem)cbCharacter.SelectedItem).Value)];
            }
        }

        private void btnAccuse_Click(object sender, EventArgs e)
        {
            if (_isAccuse)
            {
                if (cbRooms.SelectedIndex >= 0 &&
                    cbWeapons.SelectedIndex >= 0 &&
                    cbCharacter.SelectedIndex >= 0)
                {
                    if (_frm.WS.Accuse(_gameID, _player.PlayerID,
                        (Rooms)Enum.Parse(typeof(Rooms), ((ComboBoxItem)cbRooms.SelectedItem).Value),
                        (Characters)Enum.Parse(typeof(Characters), ((ComboBoxItem)cbCharacter.SelectedItem).Value),
                        (Weapons)Enum.Parse(typeof(Weapons), ((ComboBoxItem)cbWeapons.SelectedItem).Value)))
                    {
                        MessageBox.Show("Congratulations! You have solved the mystery!", "Congratulations", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        MessageBox.Show("Sorry... You have made a wrong guess. You've lost!", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please make selection.", "Select cards", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
    }
}